#!/usr/bin/env python
# -*- coding: utf-8 -*-

'''
Author: Bruno Alves 
Date: 2012/02/10
Version: v1.0
'''


import time
import urllib2
from BeautifulSoup import BeautifulSoup
from DrawPlot import Plot
from CSV import Csv


#Manage HTML 
class Soup:
   
    def __init__(self):
        pass
  
    def HTTPTags(self, http_address):

        print 'Searching HTML Tags, wait a moment...' 
        timei = time.clock()
        page = urllib2.urlopen(http_address)
        soup = BeautifulSoup(page)
        target_search1 = ['h1','h2','h3','div','p','ul','ol','img']
        target_search2 = ['H1','H2','H3','DIV','P','UL','OL','IMG']
        data = []
        for i in range(len(target_search1)):
            count = 0
            for elem in soup(target_search1[i] or target_search2[i]):
                count += 1
                pass
            data.append(count)
            pass
        timef = time.clock()
        print 'Time Elasped =', timef-timei
        print 'Finished.'
        obj1 = Csv()
        obj1.HTMLTagFile('StatsWebHTMLTags.csv',target_search2, data)
        obj2 = Plot()
        obj2.PlotHTML(data, target_search2)


